package com.company.cloud.base.modules.app.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.company.cloud.base.modules.app.controller.req.RegionListQueryParam;
import com.company.cloud.base.modules.cache.models.RegionModel;
import com.company.cloud.base.modules.cache.service.RegionCacheService;
import com.company.cloud.common.asserts.ValidatorUtils;
import com.company.cloud.common.bean.BaseResult;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * <p>
 * 地区信息表 Controller
 * </p>
 *
 * @author limengjie
 * @since 2020-05-25
 */
@RestController
@RequestMapping("/app/base/regionInfo")
@Api(tags = "App_Base_地区信息 ")
public class RegionAppController {

	@Autowired
	private RegionCacheService regionCacheService;

	@PostMapping("/queryList")
	@ApiOperation(value = "下拉框查询", response = RegionModel.class)
	public BaseResult queryList(@RequestBody RegionListQueryParam params) {
		ValidatorUtils.validate(params);
		return BaseResult.ok(regionCacheService.getRegionList(params.getParentCode()));

	}

	@PostMapping("/queryAll")
	@ApiOperation(value = "获取所有地区信息", response = RegionModel.class)
	public BaseResult queryAll(@RequestParam("level") String level) {
		return BaseResult.ok(regionCacheService.getRegionAll(level));
	}

	@PostMapping("/queryHot")
	@ApiOperation(value = "热门地区查询", response = RegionModel.class)
	public BaseResult queryHot() {
		return BaseResult.ok(regionCacheService.getHotRegion());
	}

}
